home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Documentation / Tech Notes & Articles / Recipes / Standards / Parameters < prev   
Encoding:
Text File  |  1995-03-21  |  7.7 KB  |  111 lines  |  [TEXT/ttxt]

  1. OpenDoc™ Recipes
  2.  
  3.  
  4. Parameters and Memory in OpenDoc
  5. By OpenDoc Design Team
  6. 3/10/95
  7.  
  8.  
  9. © 1993-1995  Apple Computer, Inc. All Rights Reserved.
  10. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  11. Mac and OpenDoc are trademarks of Apple Computer, Inc. 
  12.  
  13.  
  14. Overview:
  15.  
  16. This document describes the storage (or memory) responsibility of client arguments (or parameters). It first outlines the CORBA standard and then it goes into specific details pertaining to OpenDoc.
  17.  
  18. CORBA Standard1 :
  19.  
  20. In order to understand what are the storage (or memory) responsibility of client arguments, it is best to review the CORBA standard:
  21.  
  22. 1) A client is responsible for providing storage for all arguments passed as in arguments.
  23.  
  24. 2) A client is responsible forproviding storage for all out arguments and return results except in the following cases:
  25.  
  26.                                                                                                                                                                                                                                                         inout                                                                                                                                                                                                                                                    out                                                                                                                                                                                                                                                    return result                                                                                                                    
  27. short                                                                                                                                                                                                                                    1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  28. long                                                                                                                                                                                                                                            1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  29. ushort                                                                                                                                                                                                                        1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  30. ulong                                                                                                                                                                                                                                1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  31. float                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  32. double                                                                                                                                                                                                                     1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
  33. boolean                                                                                                                                                                                                            1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  34. char                                                                                                                                                                                                                                                1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  35. octet                                                                                                                                                                                                                                             1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  36. enum                                                                                                                                                                                                                                     1                                                                                                                                                                                                                                                         1                                                                                                                                                                                                                                                                             1
  37. object reference                                                                                                       2                                                                                                                                                                                                                                                         2                                                                                                                                                                                                                                                                             2
  38. struct                                                                                                                                                                                                                                    1                                                                                                                                                                                                                                                          1                                                                                                                                                                                                                                                                             1
  39. union                                                                                                                                                                                                                                 1                                                                                                                                                                                                                                                          1                                                                                                                                                                                                                                                                             1
  40. string                                                                                                                                                                                                                                    1                                                                                                                                                                                                                                                          3                                                                                                                                                                                                                                                                            3
  41. sequence                                                                                                                                                                                                1                                                                                                                                                                                                                                                          4                                                                                                                                                                                                                                                                             4
  42. array                                                                                                                                                                                                                                        1                                                                                                                                                                                                                                                          1                                                                                                                                                                                                                                                                             3
  43. any                                                                                                                                                                                                                                                      4                                                                                                                                                                                                                                                             4                                                                                                                                                                                                                                                                             4
  44.  
  45.  
  46. Case 1:
  47.  
  48. The client is responsible for providing storage and managing release of the storage. That is, the system allocates storage which must be free using ORBFree() for the following types and directions: string/out, string/return, sequence/out, sequence/return, array/return, any/inout, any/out, any/return. For inout strings and sequences, the out result is constrained by the size of the type on input.
  49.  
  50. Case 2:
  51.  
  52. The client is responsible for providing the storage used to contain the object reference. When the reference is no longer needed, the client uses the release function to release the storage associated with the reference.
  53.  
  54. Case 3:
  55.  
  56. The ORB provides the storage for these returned parameters and results. The client is responsible for releasing the storage using ORBFree.
  57.  
  58. Case 4:
  59.  
  60. The client provides the storage for the structure which contains the description of the sequence or any and the client manages release of the storage and the descriptor. The ORB prvoides storage for the values returned and puts the pointers to this storage in the descriptor structures. The client is responsible for releasing this storage using ORBFree.
  61.  
  62.  
  63. Implication to OpenDoc
  64.  
  65. If you are a client (i.e., caller) of an OpenDoc API,
  66.  
  67.                                                                                                                                                                             in                                            out                                    inout
  68.  
  69. Allocation                 Stack                                        N/A                                      Stack
  70.                                                          ODNewPtr                                                                             ODNewPtr            
  71. Deallocation            ODDisposePtr                ODDisposePtr            ODDisposePtr
  72.  
  73. If you are a callee (i.e, methods of OpenDoc classes),
  74.  
  75.  
  76.                                                                                                                                                                             in                                            out                                    inout
  77.  
  78. Allocation                 N/A                                            ODNewPtr                     ODNewPtr
  79. Deallocation            N/A                                            N/A                                        N/A
  80.  
  81.  
  82. Implication to Parts (i.e., client to OpenDoc API)
  83.  
  84.  
  85.                                                                                                                                                                             in                                            out                                    inout
  86.  
  87. Allocation                 SOMMalloc                        N/A                                         SOMMalloc
  88.                                                          ODNewPtr                                                                        ODNewPtr
  89.                                                          Stack                                                                                     Stack            
  90. Deallocation            SOMFree                       SOMFree                      SOMFree
  91.                                                          ORBFree                                ORBFree                            ORBFree
  92.                                                  ODDisposePtr                ODDisposePtr            ODDisposePtr
  93.  
  94. Other Rules:
  95.  
  96. 1) A callee must not modify in-parameters.
  97.  
  98. 2) A callee must not store an in-parameter. You must duplicate the in-parameter. 
  99.  
  100. 3) Avoid ODObject/inout even though CORBA allows it.
  101.  
  102. If you want to change the state or content of an ODObject, an in-parameter is sufficient. If you want to return an ODObject, an out-parameter should be used.
  103.  
  104. ODObject/inout is strange because the incoming object may be deleted and a new object is created and returned. It is difficult to figure out whether the original object gets returned or not.
  105.  
  106. 4) Don’t reallocate memory for string/inout and sequence/inout.
  107.  
  108. Since one cannot grow the buffer to more than the predetermined size, do NOT reallocate memory for these structs. Simply use the buffer provided.
  109.  
  110.   1 The Common Object Request Borker: Architecture and Specification (p.98-99)
  111.